package recycle.controller;

import recycle.pojo.Ordercart;
import recycle.service.OrdercartService;
import recycle.utils.Page;
import recycle.vo.OrdercartParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 描述：购物车表 控制器
* @author 孙冉
* @date 2019/07/22
*/
@RestController
@RequestMapping("/ordercart")
public class OrdercartController{
	@Resource
	private OrdercartService ordercartService;
 	
 	@RequestMapping("/findById.json")
    public Ordercart findById(Integer cartId){
        Ordercart result = null;
        try {
            result = ordercartService.findById(cartId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：获取所有的Ordercart对象
     */
    @RequestMapping("/findAll.json")
    public List<Ordercart> findAll(){
        List<Ordercart> result = null;
        try {
            result = ordercartService.findAll();
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：新增保存Ordercart对象
     */
    @RequestMapping("/save.json")
    public Map save(Ordercart ordercart){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","保存购物车表失败");
        try {
            if(ordercartService.save(ordercart)>0){
                result.put("flag",true);
                result.put("msg","保存购物车表成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：根据主键删除购物车表对象
     * @param cartId
     */
    @RequestMapping("/delete.json")
    public Map delete(Integer cartId){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","保存购物车表失败");
        try {
            if(ordercartService.delete(cartId)>0){
                result.put("flag",true);
                result.put("msg","保存购物车表成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：更新购物车表对象
     */
    @RequestMapping("/update.json")
    public Map update(Ordercart ordercart){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","更新购物车表失败");
        try {
            if( ordercartService.update(ordercart)>0){
                result.put("flag",true);
                result.put("msg","更新购物车表成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;

    }

    /**
     * 根据不确定的条件，动态查询
     */
    @RequestMapping("/query.json")
    public List<Ordercart> query(OrdercartParam param){
        List<Ordercart> result = null;
        try {
            result = ordercartService.query(param);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 根据不确定的条件，动态分页查询
     */
    @RequestMapping("/queryByPage.json")
    public Page queryByPage(OrdercartParam param){
        Page result = null;
        try {
            result = ordercartService.queryByPage(param);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }
 }
